<?php

/**
 * contact actions.
 *
 * @package    seth
 * @subpackage contact
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class contactActions extends sfActions
{
  public function executeIndex(sfWebRequest $request){
      
      
      
  }
  public function executeIndexREAL(sfWebRequest $request)
  {
    //$this->contacts = $this->getRoute()->getObjects();
       $order=$request->getParameter('orderBy', 'surname');
      //Se cambio campo ordinante metto ASC, altrimenti scambio ASC e DESC
      $orderOption= $this->getUser()->SwitchOrderOption($order);
      $this->getUser()->setOrderField($order);
      
      $this->contacts=Doctrine_Core::getTable('Contact')->getContactIndex(array(
          'orderBy'=>$order,
          'indexOrder'=>$orderOption));
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->contact = $this->getRoute()->getObject();
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new ContactForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->form = new ContactForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->form = new ContactForm($this->getRoute()->getObject());
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->form = new ContactForm($this->getRoute()->getObject());

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();
    
    $this->getRoute()->getObject()->delete();
    $this->redirect('contact/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $contact = $form->save();

      $this->redirect('contact/show?id='.$contact->getId());
    }
  }
}
